package com.samsung.controller.vote;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.samsung.common.util.BaseUtil;
import com.samsung.model.vote.VoteOption;
import com.samsung.model.vote.VoteTopic;
import com.samsung.service.vote.OptionService;
import com.samsung.service.vote.TopicService;
/**
 * 
 * @ClassName: TopicController
 * @Description: TODO(通过topicId从数据库查寻当前Topic和Option对象，并返回至jsp页面)
 * @author qin1.li
 * @date 2015年4月27日下午2:01:41
 * @sine 1.0
 */
@Controller
@RequestMapping("/vote/topic")
public class TopicController extends MultiActionController {
	@Autowired
	private TopicService topicService;
	@Autowired
	private OptionService optionService;
	
	@RequestMapping("/show")
	public ModelAndView showVote(String topicId) throws Exception{
		ModelAndView mav = new ModelAndView();
		if(BaseUtil.isEmpty(topicId)) {
			throw new Exception("投票主题编号不能为空");
		}
		VoteTopic topic = topicService.getTopic(topicId);
		List<VoteOption> optionList = optionService.listByTopic(topicId);
		mav.addObject("topic",topic);
		mav.addObject("optionList",optionList);
		mav.addObject("topicId",topicId);
		mav.setViewName("vote/voteDetail");
		return mav;
	}
	
}
